﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UFIDA.U9.SCM.SM.SOUIModel;
using UFSoft.UBF.UI.WebControlAdapter;
using UFSoft.UBF.UI.ControlModel;
using UFSoft.UBF.UI.MD.Runtime;
using UFSoft.UBF.UI.Engine.Builder;
using System.Data;
using UFSoft.UBF.Util.DataAccess;
using UFSoft.UBF.Sys.Database;
using UFSoft.UBF.UI.ActionProcess;
using UFSoft.UBF.UI.WebControls.Association.Adapter;
using UFSoft.UBF.UI.WebControls.Association;
using UFSoft.UBF.UI.WebControls.ClientCallBack;
using System.Collections;
using System.Collections.Specialized;
using UFSoft.UBF.UI.Controls;
using UFSoft.UBF.UI.WebControls;
using UFIDA.U9.UI.PDHelper;
using UFSoft.UBF.Business;
using UFSoft.UBF.View.Query;
using UFSoft.UBF.UI.IView;
using UFIDA.U9.Cust.Cli.PlugUI;
using System.Web.UI.WebControls.WebParts;

namespace UFIDA.U9.Cust.U9Demo.PlugUI
{
    public class SOMainUIFormWebPart : UFSoft.UBF.UI.Custom.ExtendedPartBase
    {
        private UFIDA.U9.SCM.SM.SOUIModel.StandardSOMainUIFormWebPart part;
        IUFDataGrid DataGrid4;
        //配置文件XX.config文件拷贝到portal下，dll文件放置到portal/UILib下
        //配置文件以WebPartExtend开头
        public override void AfterInit(UFSoft.UBF.UI.IView.IPart Part, EventArgs args)
        {
            //首先调用原来的事件
            base.AfterInit(Part, args);
            part = Part as UFIDA.U9.SCM.SM.SOUIModel.StandardSOMainUIFormWebPart;

            if (part == null)
                return;

            DataGrid4 = (IUFDataGrid)part.GetUFControlByName(part.TopLevelContainer, "DataGrid4");

            #region 1.Toobar上添加按钮：页面扩展-加按钮
            // （1）、实例化按钮
            IUFButton btnPRToPM = new UFWebButtonAdapter();
            
            //（2）、加入功能栏Card中
            IUFToolbar toolbar = (IUFToolbar)part.GetUFControlByName(part.TopLevelContainer, "Toolbar1");

            if (toolbar != null)
            {
                string guid = "047FC9F5-46C0-449A-83C2-2822BCF24012";// 在数据库生成下GUID，或者修改下这里的值。SELECT NEWID()
                btnPRToPM = UIControlBuilder.BuilderToolbarButton(toolbar, "True", "btnPRToPM", "True", "True", 70, 28, "7", "", true, false,
                    guid, guid, guid);
                UIControlBuilder.SetButtonAccessKey(btnPRToPM);
                btnPRToPM.Text = "拉单销售订单";
                btnPRToPM.ID = "BtnQuerySaleOrder";
                btnPRToPM.AutoPostBack = true;
                btnPRToPM.UIModel = part.Model.ElementID;
                ((UFWebToolbarAdapter)toolbar).Items.Add(btnPRToPM as System.Web.UI.WebControls.WebControl);
                btnPRToPM.Click += new EventHandler(btnPRToPM_Click);


            }
            #endregion

            //2.Card里面增加按钮
            //设置按钮在容器中的位置
            #region 2.Card里面增加按钮
            IUFCard card = (IUFCard)part.GetUFControlByName(part.TopLevelContainer, "Card0");
            IUFButton btnPRToPM2 = new UFWebButtonAdapter();
            btnPRToPM2.Text = "拉单销售订单";
            btnPRToPM2.ID = "BtnQurySaleOrder1";
            btnPRToPM2.AutoPostBack = true;
            card.Controls.Add(btnPRToPM2);
            //btnPRToPM2.Click += new EventHandler(BtnPRToPM2_Click);
            CommonFunction.Layout(card, btnPRToPM2, 16, 0);   //一般为从左往右按钮个数乘以2
            #endregion

            //3、Card的DropDownButton里面添加按钮
            #region Card的DropDownButton里面添加按钮
            IUFMenu btnPRToPM1 = new UFWebMenuAdapter();
            btnPRToPM1.Text = "拉单销售订单";
            btnPRToPM1.ID = "BtnQurySaleOrder2";
            btnPRToPM1.AutoPostBack = true;
            IUFDropDownButton menuButtion = (IUFDropDownButton)CommonFunction.FindControl(part, "Card0", "DDBtnOperation");
            if (menuButtion != null)
            {
                btnPRToPM1.ItemClick += BtnPRToPM1_ItemClick;
                menuButtion.MenuItems.Add(btnPRToPM1);
            }
            #endregion



        }

        private void BtnPRToPM1_ItemClick(object sender, MenuItemClickEventArgs e)
        {
            throw new NotImplementedException();
        }

        private void BtnPRToPM2_Click(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }

        void btnPRToPM_Click(object sender, EventArgs e)
        {
           
        }

        public override void BeforeEventProcess(IPart Part, string eventName, object sender, EventArgs args, out bool executeDefault)
        {

            base.BeforeEventProcess(Part, eventName, sender, args, out executeDefault);
        }

        public override void AfterEventProcess(UFSoft.UBF.UI.IView.IPart Part, string eventName, object sender, EventArgs args)
        {
            UFSoft.UBF.UI.WebControlAdapter.UFWebButton4ToolbarAdapter webButton = sender as UFSoft.UBF.UI.WebControlAdapter.UFWebButton4ToolbarAdapter;
            //获取提交按钮点击后事件，加自己的逻辑判断
            if (webButton != null && webButton.Action == "SubmitClick")
            {
                part.CurrentSessionState["XXX"] = "xxx";
            }
            base.AfterEventProcess(Part, eventName, sender, args);

        }

        public override void AfterRender(IPart Part, EventArgs args)
        {
            base.AfterRender(Part, args);
        }

        public override void BeforeRender(IPart Part, EventArgs args)
        {
            base.BeforeRender(Part, args);
        }


    }
}
